#!/usr/bin/env ruby

require 'json'
cmd_args = ARGV[0]
c = JSON.parse(ARGV[1])

$stdout.sync = true
cmd_output = %x{ df #{cmd_args} }

lines = cmd_output.split(/\n/)

headers = lines.shift()
output  = {}

lines.each do |line|
  (fs, size, used, avail, use, mounted_on) = line.split 
  h = { :fs => fs, :size => size, :used => used, :avail => avail, :percentage => use, :mounted_on => mounted_on } 
  output[fs] = { :size => size, :used => used, :free => avail }
end

puts JSON.generate(:output => output)
